package cn.com.xjnt.vas.manage.domain.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * The persistent class for the sys_permission database table.
 * 
 */
@Entity
@Table(name = "sys_permission")
@NamedQuery(name = "Permission.findAll", query = "SELECT p FROM Permission p")
public class Permission extends com.frameworks.core.entity.IdEntity {
	private static final long serialVersionUID = 1L;

	@Column(nullable = false, length = 60)
	private String name;

	@Column(nullable = false, length = 60)
	private String code;

	@Column(length = 256)
	private String description;

	@ManyToOne
	@JoinColumn(name = "module_id")
	private Module module;

	@OneToMany(mappedBy = "permission", cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, orphanRemoval = true)
	private List<RolePermission> rolePermissions = new ArrayList<RolePermission>(0);

	public Permission() {
	}
	
	public Permission create(String name, String code, String description) {
		this.name = name;
		this.code = code;
		this.description = description;
		return this;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Module getModule() {
		return module;
	}

	public void setModule(Module module) {
		this.module = module;
	}

	public List<RolePermission> getRolePermissions() {
		return rolePermissions;
	}

	public void setRolePermissions(List<RolePermission> rolePermissions) {
		this.rolePermissions = rolePermissions;
	}
	
}